package com.devunion.bogdan.view.util;

import javax.swing.*;
import java.awt.*;

/**
 * User: user
 * Date: 06.11.2004
  */
public class TabbedPaneManager {
    public static final String TABBED_PANE_EDITOR_NAME = "Editor Pane";
    public static final String TABBED_PANE_OUTPUT_NAME = "Output Pane";

    private static Frame mainFrame;

    static {
        mainFrame = DialogHelper.getMainFrame();
    }

    public static JTabbedPane getTabbedPaneEditor() {
        return lookupPaneForName(mainFrame, TABBED_PANE_EDITOR_NAME);
    }

    public static JTabbedPane getTabbedPaneOutput() {
        return lookupPaneForName(mainFrame, TABBED_PANE_OUTPUT_NAME);
    }

    private static JTabbedPane lookupPaneForName(Container root, String name) {
        Component[] components = root.getComponents();

        for (int i=0; i < components.length; i++) {
            if (name.equals(components[i].getName())) {
                return (JTabbedPane) components[i];
            }
              else if (components[i] instanceof Container) {
                  JTabbedPane res = lookupPaneForName((Container) components[i], name);

                if (res instanceof JTabbedPane) {
                    return res;
                }
            }
        }
        return null;
    }
}
